@use 'utils/variables';

.AdvancedTextEditor__skeleton {
    display: flex;
    height: 122px;
    align-items: center;
    justify-content: center;
    padding-left: 10px;
    border: 2px solid rgba(var(--center-channel-color-rgb), 0.16);
    border-radius: 4px;
    margin: 0 24px 24px;
    color: rgba(var(--center-channel-color-rgb), 0.75);

    .btn {
        margin: 10px
    }
}

.AdvancedTextEditor {
    &__ctr {
        form {
            padding: unset;
        }
    }
    position: relative;

    display: flex;
    width: 100%;
    flex-direction: row;
    align-items: end;
    padding: 0 24px;
    margin: 0 auto;
    gap: 12px;
    justify-items: stretch;

    .sidebar--right & {
        padding-top: 12px;

        .AutoHeight {
            position: absolute;
            bottom: 0;
            left: 0;
        }
    }

    .ThreadViewer & {
        padding-top: 0px;

        .AutoHeight {
            position: absolute;
            bottom: 0;
            left: 0;
        }
    }

    .custom-textarea {
        // fix for a miscalculation due to the heavily overwritten custom-textarea class
        height: 0;
        padding-right: calc(16px + var(--right-padding-for-scrollbar) + var(--right-padding-for-preview-button));
        box-shadow: none;

        &:focus {
            box-shadow: none;
        }

        &.textbox-preview-area {
            height: auto;
            padding-right: 20px;
            white-space: normal;

            blockquote:before {
                top: 9px;
            }
        }
    }

    /* stylelint-disable length-zero-no-unit */
    --right-padding-for-scrollbar: 0px;
    --right-padding-for-preview-button: 0px;
    /* stylelint-enable length-zero-no-unit */

    &.scroll {
        --right-padding-for-scrollbar: 8px;
    }

    // With the formatting bar disabled, leave room on the right for the post controls until the text takes up
    // multiple lines. At that point, leave space below the text as if the controls were still there.
    &.formatting-bar {
        --right-padding-for-preview-button: 32px;
    }

    &__body {
        position: relative;
        max-width: 100%;
        flex: 1;
        border: 2px solid rgba(var(--center-channel-color-rgb), 0.16);
        border-radius: 4px;
        background-color: var(--center-channel-bg);

        &:focus-visible,
        &:focus-within,
        &:focus-visible:hover,
        &:focus-within:hover {
            border: 2px solid rgba(var(--center-channel-color-rgb), 0.32);
            outline: none;
            outline-offset: 0;
        }

        &:hover {
            border: 2px solid rgba(var(--center-channel-color-rgb), 0.24);
        }

        &[disabled] {
            &:hover {
                border: none;
            }
        }
    }

    &__action-button {
        display: flex;
        width: 32px;
        height: 32px;
        flex-shrink: 0;
        align-items: center;
        justify-content: center;
        padding: 0;
        border: none;
        border-radius: 4px;
        background: transparent;
        color: rgba(var(--center-channel-color-rgb), 0.75);
        cursor: pointer;
        fill: currentColor;

        &:hover {
            background: rgba(var(--center-channel-color-rgb), 0.08);
            color: rgba(var(--center-channel-color-rgb), 0.8);
            fill: currentColor;
            text-decoration: none;
        }

        &.hidden {
            visibility: hidden;
        }

        &+input {
            position: absolute;
            top: 0;
            right: 0;
            width: 100%;
            height: 100%;
            margin: 0;
            cursor: pointer;
            direction: ltr;
            font-size: 23px;
            opacity: 0;
            pointer-events: none;
        }
    }

    &__action-button--active {
        background: rgba(var(--button-bg-rgb), 0.08);
        color: rgb(var(--button-bg-rgb));
        fill: currentColor;
    }

    &__cell {
        position: relative;
        display: flex;
        flex-direction: column;
        vertical-align: top;
    }

    &__helper-text {
        display: inline-block;
        margin: 8px 0 4px;
        color: rgba(var(--center-channel-color-rgb), 0.75);
        font-family: "Open Sans", sans-serif;
    }

    &__footer {
        position: relative;
        display: flex;
        flex-direction: column;
        padding: 0 24px;
        font-size: 12px;

        .help__text {
            text-align: right;

            a,
            button {
                margin-left: 10px;
            }
        }

        .has-error,
        .post-error {
            margin: 4px 0 0 0;
            color: var(--error-text);
        }
    }

}

@media screen and (max-width: 768px) {
    #post-create {
        .AdvancedTextEditor {
            padding: 0;

            &__body {
                border-radius: 0;
                border-right: none;
                border-left: none;

                &:focus-visible,
                &:focus-within,
                &:focus-visible:hover,
                &:focus-within:hover,
                &:hover {
                    border-right: none;
                    border-left: none;
                }
            }

            .ThreadViewer & {
                .msg-typing:empty {
                    display: none;
                }
            }
        }
    }

    .sidebar--right .post-create__container {
        form {
            padding: 0;
        }
    }
}

.msg-typing {
    display: block;
    overflow: hidden;
    height: 20px;
    margin-bottom: 5px;
    color: rgba(var(--center-channel-color-rgb), 0.75);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
